﻿using System;
using System.Collections.Generic;
using System.Linq;
using Ants;
using SettlersEngine;
using System.Drawing;
using System.IO;

namespace AntsBot
{
    public class Scatter : Strategy
    {
        public Scatter(AntLoc ant) : base(StrategyTypes.Scatter, ant) { }

        public override Goal GetGoal()
        {
            var rng = new Random((int)DateTime.Now.TimeOfDay.TotalMilliseconds % 265407);

            // wander aimlessly
            foreach (var d in Ants.Ants.Aim.Values.OrderBy(c => rng.Next()))
            {
                var loc = Ant.GetDestination(d);
                if (loc.IsPassable())
                {
                    var path = new LinkedList<Tile>();
                    path.AddFirst(new Tile(TileType.Unseen, Ant));
                    path.AddLast(new Tile(TileType.Unseen, loc));
                    return new Goal(Ant, path, (s => Ant.State.FoodTiles.Any()), StrategyTypes.Scatter);
                }
            }

            return null;
        }
    }
}